<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2018/1/24
 * Time: 21:54
 */

namespace app\common\model;


class Page
{
    public $totalpage;
    //每页默认包含10条数据
    public $pagesize = 10;

    public $totalrecord;
    public $pagenum;
    //起始索引
    public $startindex;

    public $startPage;
    public $endPage;
    public $pagenums;//标签列表
    public function __construct($pagenum,$totalrecord,$pagesize)
    {
        $this->pagenum = $pagenum;
        $this->totalrecord = $totalrecord;
        $this->pagesize= $pagesize;
        $this->totalpage = floor(($this->totalrecord+$this->pagesize-1)/$this->pagesize);
        $this->startindex = ($this->pagenum-1)*$this->pagesize;
        if($this->totalpage<=5){
            $this->startPage = 1;
            $this->endPage = $this->totalpage;
        }else{
            $this->startPage = $pagenum-2;
            $this->endPage = $pagenum+2;
            if($this->startPage<1){
                $this->startPage = 1;
                $this->endPage = 5;
            }
            if($this->endPage>$this->totalpage){
                $this->endPage = $this->totalpage;
                $this->startPage = $this->totalpage-4;
            }
        }
        for($i = $this->startPage;$i<=$this->endPage; $i++){
            $this->pagenums[]=$i;
        }
    }
}